package com.Dubbo.test.provider.service.demo;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.Dubbo.api.test.demo.entity.Demo;
import com.Dubbo.api.test.demo.service.IDemoService;
import com.Dubbo.test.provider.dao.demo.DemoMapper;

@Service(value = "demoService")
public class DemoServiceImpl implements IDemoService{

	@Resource(name = "demoMapper")
	private DemoMapper demoMapper;

	@Override
	public String selectNameByPrimaryKey(Integer id) {
		Demo demo = demoMapper.selectByPrimaryKey(id);
		if(demo == null) {
			System.out.println("demoMapper.selectByPrimaryKey(id) == null");
			return null;
		} else {
			System.out.println("demoMapper.selectByPrimaryKey(id) != null");
			return demo.getName();
		}
	}

	/**
	 * 此方法返回主键id
	 * 如果insert操作更新的行数  >0 的话，返回主键id; 如果更新的行数不大于0的话，返回0；
	 */
	@Override
	public int insertEntity(Demo demo) {
		int insertEntityReturnId = demoMapper.insertEntity(demo);
		if(insertEntityReturnId > 0) {
			return demo.getId();
		} else {
			return 0;
		}
	}

	@Override
	public int insert2Entity(Demo demo1, Demo demo2) {
		int insertEntity1ReturnId = demoMapper.insertEntity(demo1);
		int insertEntity2ReturnId = demoMapper.insertEntity(demo2);
		if(insertEntity1ReturnId > 0 && insertEntity2ReturnId > 0) {
			return 1;
		} else {
			return 0;
		}
	}
	
	
}
